#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import base64
import random
import time
from io import BytesIO
import cv2
from PIL import Image
from selenium.webdriver import ActionChains

from common.readelement import Element
from page_object.webpage import WebPage
from tools.logger import Log

createParttimeResume = Element('jzsz/personal/create_parttime_resume')


class CreateParttimeResumePage(WebPage):
    """添加兼职简历类"""

    def username(self):
        """用户信息"""
        self.is_click(createParttimeResume['用户信息'])
        self.is_click(createParttimeResume['兼职发布'])

    def get_resume_num(self):
        """添加前获取已发布的兼职"""
        res = self.is_exists2(createParttimeResume['兼职总量'])  # 可能会存在已发布为空，在获取数量前先判断兼职总量元素是否存在
        if res:
            text = self.find_element(createParttimeResume['兼职总量']).text
            jobnum = text[2:-2]
            return jobnum
        else:
            return '0'

    def add_resume(self):
        """添加简历"""
        self.is_click(createParttimeResume['添加信息'])

    def add_resume_content(self,salarymin,salarymax,endtime):
        """简历内容"""
        self.is_click(createParttimeResume['岗位类型'])
        self.is_click(createParttimeResume['选择岗位'])
        self.is_click(createParttimeResume['意向地区'])
        self.is_click(createParttimeResume['选择地区'])
        self.is_click(createParttimeResume['其他'])
        # self.click_blank_area()
        self.is_click(createParttimeResume['结算方式'])
        self.is_click(createParttimeResume['选择方式'])
        self.input_text(createParttimeResume['最小薪资'], salarymin)
        self.input_text(createParttimeResume['最大薪资'], salarymax)
        self.is_click(createParttimeResume['开始时间'])
        self.is_click(createParttimeResume['选择开始时间'])
        self.input_text(createParttimeResume['结束时间'], endtime)
        self.is_click(createParttimeResume['工作地点'])
        self.is_click(createParttimeResume['选择工作地点'])

    def release_resume(self):
        """发布简历"""
        self.focus()
        self.is_click(createParttimeResume['发布'])

    def create_success(self, resume_num):
        """验证创建成功"""
        res = self.is_exists2(createParttimeResume['兼职总量'])
        if res:
            text = self.find_element(createParttimeResume['兼职总量']).text  # 获取创建成功后的全职总量
            resume_num2 = text[2:-2]
            if int(resume_num2) == int(resume_num) + 1:
                return True
            else:
                return False
        else:
            return False





